package com.fawvwebanma.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fawvwebanma.dto.TrainDto;
import com.fawvwebanma.entity.Train;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface TrainMapper extends BaseMapper<Train> {
    @Select("select * from train where train_num = #{trainNum}")
    @Results(//id="PersonSkill",//如果PersonSkillDto类没有加@TableName注解，字段会自动匹配，id是否设置没有影响，如果加了注解，id的值要与注解设置的value一致
            value = {
                    @Result(property = "trainNum",column = "train_num"),
                    @Result(property = "trainPassStationDtos",javaType = List.class,column = "train_num",
                            many = @Many(select = "com.fawvwebanma.mapper.TrainPassStationMapper.selectDtoByTrainNum"))})
    TrainDto getTrainByTrainNum(@Param("trainNum") String trainNum);

    @Select("select train_num from traindate where train_num = #{trainNum} and run_date = #{date}")
    TrainDto getTrainOnDate(@Param("trainNum") String trainNum,@Param("date") String date);
}
